package com.morehair.controller.admin;

import com.morehair.bean.bo.admin.GroupOnRulesBo;
import com.morehair.bean.pojo.GrouponRules;
import com.morehair.bean.vo.admin.BaseRespVo;
import com.morehair.bean.vo.admin.TotalAndItemsVo;
import com.morehair.service.admin.GroupOnService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author  kkw
 * Date  2021/6/9 21:02
 * Version 1.0
 * Description :
 */
@RestController
@RequestMapping("admin/groupon/")
public class GroupOnController {
    @Autowired
    GroupOnService groupOnService;

    @GetMapping("list")
    @RequiresPermissions("admin:groupon:list")
    public BaseRespVo getGroupOnRules(Integer page,Integer limit,Integer goodsId,String sort,String order) {
        TotalAndItemsVo<GrouponRules> totalAndItemsVo=groupOnService.getGroupOnRules(page,limit,goodsId,sort,order);
        return BaseRespVo.ok(totalAndItemsVo);
    }


    @PostMapping("create")
    @RequiresPermissions("admin:groupon:create")
    public BaseRespVo createGroupOn(@RequestBody GroupOnRulesBo groupOnRulesBo) {
        GrouponRules groupOnRules=groupOnService.createGroupOnRules(groupOnRulesBo);
        if (groupOnRules==null) {
            return BaseRespVo.fail(402,null,"没有该商品信息");
        }
        return BaseRespVo.ok(groupOnRules);
    }

    @PostMapping("delete")
    @RequiresPermissions("admin:groupon:delete")
    public BaseRespVo deleteGroupOn(@RequestBody GrouponRules grouponRules) {
        groupOnService.deleteGroupOnRules(grouponRules);
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    @RequiresPermissions("admin:groupon:update")
    public BaseRespVo updateGroupOn(@RequestBody GrouponRules grouponRules) {
        boolean b=groupOnService.updateGroupOnRules(grouponRules);
        if (b) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail(402,null,"没有该商品信息");
    }

}
